﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using DoeObjects;
using System.Web.Mvc;
using DoeLibsMVC.Security;

namespace DoeLibsMVC.Models
{
	public class RegisterModel
	{
		public RegisterModel()
		{
			_staffMembers = new List<User>();
			List<User> users = User.getUsersOfCategory(UserCategoryHelper.STAFF_CATEGORY);
			foreach (User u in users)
				if (u.Activated) _staffMembers.Add(u);
		}

		[Required]
        [DataType(DataType.EmailAddress)]
		[Display(Name = "E-Mail")]
		public string EMail { get; set; }

		[Required]
		[DataType(DataType.Password)]
		[Display(Name = "Password")]
		public string Password { get; set; }

		[Required]
		[DataType(DataType.Password)]
		[Display(Name = "Confirm password")]
		public string ConfirmPassword { get; set; }

		[Required]
		[Display(Name = "First name")]
		public string FirstName { get; set; }

		[Required]
		[Display(Name = "Last name")]
		public string LastName { get; set; }

        [Required]
        [Display(Name= "Category")]
		public int CategoryId { get; set; }

        private List<UserCategory> _categories = UserCategory.getAll();
        public IEnumerable<SelectListItem> Categories
        {
            get
            {
                return new SelectList(_categories, "CategoryId", "Name");
            }
        }
        [Required]
        [Display(Name="Acceptor")]
        public int AcceptorId { get; set; }

        private List<User> _staffMembers;
        public IEnumerable<SelectListItem> StaffMembers
        {
            get
            {
                var dynStaffMembers = _staffMembers.Select(u => new { id = u.UserId, display = string.Format("{0} {1} ({2})", u.FirstName, u.LastName, u.Room) }).ToList();
                return new SelectList(dynStaffMembers, "id", "display");
            }
        }

        [Display(Name = "Room")]
        public string Room { get; set; }

        [Display(Name = "Uni Phone")]
        public string UniPhone { get; set; }
	}
}